﻿using System;
using System.Linq;
using Stamp_For_Africa_Version_2.Models;

namespace Stamp_For_Africa_Version_2.Repositories
{
  public class ArtistRepository
  {
    private StampsDataContext db = new StampsDataContext();
    //
    // Query Methods

    public IQueryable<Artist> FindAllArtists()
    {
      return db.Artists;
    }

    public IQueryable<Artist> FindAllArtists(String filterName, String filterSurname)
    {
      //Filter code comes here
      return db.Artists.Where(u => u.Name.ToLower().Contains(filterName.ToLower()) && u.Surname.ToLower().Contains(filterSurname.ToLower()));

    }

    public Artist GetArtist(Guid id)
    {
      return db.Artists.SingleOrDefault(d => d.Id == id);
    }

    //
    // Insert/Delete Methods

    public void Add(Artist artist)
    {
      db.Artists.InsertOnSubmit(artist);
    }

    public void Delete(Artist artist)
    {
      db.Artists.DeleteOnSubmit(artist);
    }

    //
    // Persistence

    public void Save()
    {
      db.SubmitChanges();
    }
  }
}